#include "eventloop/Eventloop.h"
#include "eventloop/EventloopThread.h"
#include "thread/current_thread.h"

#include <cstdio>
#include <unistd.h>

void runInThread()
{
  printf("runInThread(): pid = %d, tid = %d\n",
         getpid(), CurrentThread::tid());
}

int main()
{
  printf("main(): pid = %d, tid = %d\n",
         getpid(), CurrentThread::tid());

  EventloopThread loopThread;
  loopThread.start();
  Eventloop* loop = &loopThread.eventloop();
  // 异步调用runInThread，即将runInThread添加到loop对象所在IO线程，让该IO线程执行
  loop->run_in_loop(runInThread);
  sleep(1);
  // runAfter内部也调用了runInLoop，所以这里也是异步调用
  loop->run_after(2, runInThread);
  sleep(5);
  loop->quit();

  printf("exit main().\n");
}